package com.hongxun.design.BroadCastReceivers;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;

import java.util.List;

import com.hongxun.design.MyApp;
import com.hongxun.design.mytools.MyLog;
import com.hongxun.design.utils.wifiutil.OpretionsType;


/**
 * Created by zerdoor_pc on 2016/4/18.
 */
public class WifiStateBroadCast extends BroadcastReceiver {
    private WifiBroadCastOperations operations;

    private OpretionsType type;

    private String SSID;

    public WifiStateBroadCast(WifiBroadCastOperations operations, String SSID) {

        this.operations = operations;
        this.SSID = SSID;
    }

    public void setOpType(OpretionsType type) {
        this.type = type;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        if (WifiManager.WIFI_STATE_CHANGED_ACTION.equals(intent.getAction())) {// 这个监听wifi的打开与关闭，与wifi的连接无关
            int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, 0);
            MyLog.L(MyApp.AppName + "WIFI状态wifiState" + wifiState);
            switch (wifiState) {
                case WifiManager.WIFI_STATE_DISABLED:
                    break;
                case WifiManager.WIFI_STATE_DISABLING:
                    break;
                case WifiManager.WIFI_STATE_ENABLED:
                    if (type != null) {
                        operations.operationByType(type, SSID);
                    }
                    break;
            }
        }

    }




    public interface WifiBroadCastOperations {

        /**
         * @param wifiList 热点扫描结果
         */
        void disPlayWifiScanResult(List<ScanResult> wifiList);

        /**
         * @param result wifi 连接结果
         * @param wifiInfo wifi连接信息
         * @return wifi连接结果
         */
        boolean disPlayWifiConResult(boolean result, WifiInfo wifiInfo);

        /**
         * @param type conntect wifi or scan wifi
         * @param SSID wifi 连接时指定的SSID
         */
        void operationByType(OpretionsType type, String SSID);

    }
}
